package com.wlz.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.core.task.SimpleAsyncTaskExecutor;

/**
 *  事件监听器配置类
 * @author wlz
 * @date 2022-05-23  9:27 下午
 */
@Configuration
@ComponentScan("com.wlz.eventListener")
public class AppConfig6 {

	/**
	 *  事件监听机制 异步处理  bean id 必须叫 applicationEventMulticaster
	 * @return
	 */
	@Bean("applicationEventMulticaster") // step1: id 必须叫 applicationEventMulticaster
	public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
		// step2: 实例化 SimpleApplicationEventMulticaster
		SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();
		// Step3: 设置TaskExecutor
		eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
		return eventMulticaster;
	}

}
